package com.ktwlsoft.archivemanage.controller.guiBusiness;

import com.ktwlsoft.archivemanage.domain.business.businessService.guiBusiness.GuidanceApplyService;
import com.ktwlsoft.archivemanage.domain.dao.entity.guiBusiness.GuidanceApply;
import com.ktwlsoft.archivemanage.payload.Result;
import com.ktwlsoft.archivemanage.payload.ResultType;
import com.ktwlsoft.archivemanage.service.security.UserAuthenticate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 指导申请控制器
 *
 * @author zhuhe on 2020/4/28 14:12
 * @version 1.0
 */
@Api(value = "指导申请控制器", description = "指导申请控制器")
@RestController
@RequestMapping("guidanceApply")
public class GuidanceApplyController {

    private final GuidanceApplyService guidanceApplyService;

    public GuidanceApplyController(GuidanceApplyService guidanceApplyService) {
        this.guidanceApplyService = guidanceApplyService;
    }

    @ApiOperation(value = "用户web-列表")
    @ResponseBody
    @GetMapping("userWebFindPage")
    public ResponseEntity<?> userWebFindPage(@RequestParam(defaultValue = "1") int pn,
                                             @RequestParam(defaultValue = "30") int pageSize,
                                             @ApiParam(name = "state", value = "状态") @RequestParam(defaultValue = "") Integer state,
                                             @ApiParam(name = "guidanceTimeStart", value = "指导时间开始") @RequestParam(defaultValue = "") String guidanceTimeStart,
                                             @ApiParam(name = "guidanceTimeEnd", value = "指导时间结束") @RequestParam(defaultValue = "") String guidanceTimeEnd,
                                             @ApiParam(name = "keyWords", value = "关键字") @RequestParam(defaultValue = "") String keyWords) {
        return ResponseEntity.ok(guidanceApplyService.findPage(pn, pageSize, state, guidanceTimeStart, guidanceTimeEnd, keyWords, "userWeb"));
    }

    @ApiOperation(value = "用户web-新增")
    @ResponseBody
    @PostMapping("userWebSave")
    public ResponseEntity<?> userWebSave(@Valid @RequestBody GuidanceApply request) {
        return ResponseEntity.ok(guidanceApplyService.save(request));
    }

    @ApiOperation(value = "用户web-提交")
    @ResponseBody
    @GetMapping("userWebCommit")
    public ResponseEntity<?> userWebCommit(@ApiParam(name = "id", value = "指导申请id") @RequestParam Long id) {
        return ResponseEntity.ok(guidanceApplyService.commit(id));
    }

    @ApiOperation(value = "用户web-编辑")
    @ResponseBody
    @PostMapping("userWebUpdate")
    public ResponseEntity<?> userWebUpdate(@Valid @RequestBody GuidanceApply request) {
        return ResponseEntity.ok(guidanceApplyService.update(request));
    }

    @ApiOperation(value = "用户web-详情")
    @ResponseBody
    @GetMapping("userWebDetails")
    public ResponseEntity<?> userWebDetails(@ApiParam(name = "id", value = "指导申请id") @RequestParam Long id) {
        return ResponseEntity.ok(guidanceApplyService.details(id));
    }

    @ApiOperation(value = "用户web-删除")
    @ResponseBody
    @GetMapping("userWebDelete")
    public ResponseEntity<?> userWebDelete(@ApiParam(name = "id", value = "指导申请id") @RequestParam Long id) {
        return ResponseEntity.ok(guidanceApplyService.delete(id));
    }

    @ApiOperation(value = "管理web-列表")
    @ResponseBody
    @GetMapping("manageWebFindPage")
    public ResponseEntity<?> manageWebFindPage(@RequestParam(defaultValue = "1") int pn,
                                               @RequestParam(defaultValue = "30") int pageSize,
                                               @ApiParam(name = "state", value = "状态") @RequestParam(defaultValue = "") Integer state,
                                               @ApiParam(name = "guidanceTimeStart", value = "指导时间开始") @RequestParam(defaultValue = "") String guidanceTimeStart,
                                               @ApiParam(name = "guidanceTimeEnd", value = "指导时间结束") @RequestParam(defaultValue = "") String guidanceTimeEnd,
                                               @ApiParam(name = "keyWords", value = "关键字") @RequestParam(defaultValue = "") String keyWords) {
        return ResponseEntity.ok(guidanceApplyService.findPage(pn, pageSize, state, guidanceTimeStart, guidanceTimeEnd, keyWords, "manageWeb"));
    }

    @ApiOperation(value = "管理web-详情")
    @ResponseBody
    @GetMapping("manageWebDetails")
    public ResponseEntity<?> manageWebDetails(@ApiParam(name = "id", value = "指导申请id") @RequestParam Long id) {
        return ResponseEntity.ok(guidanceApplyService.details(id));
    }

    @ApiOperation(value = "管理web-验证")
    @ResponseBody
    @GetMapping("manageWebVerification")
    @UserAuthenticate(actionCode = "GUIDANCEAPPLY_VERIFICATION")
    public ResponseEntity<?> manageWebVerification(@ApiParam(name = "id", value = "指导申请id") @RequestParam Long id,
                                                   @ApiParam(name = "remark", value = "验证备注") @RequestParam(defaultValue = "") String remark,
                                                   @ApiParam(name = "verification", value = "是否通过:true.是,false.否") @RequestParam(defaultValue = "") Boolean verification) {
        return ResponseEntity.ok(guidanceApplyService.verification(id, remark, verification));
    }
}